package com.dongdongshop.mapper;

import com.dongdongshop.pojo.TbGoodsES;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GoodsESMapper extends ElasticsearchRepository<TbGoodsES,Long> {
    /**
     * 关键字检索
     * @param goodsName
     * @return
     */
    @Highlight(
            fields = {
                    @HighlightField(name = "goods_name")
            },
            parameters = @HighlightParameters(
                    preTags = "<strong><span style='color:red'>",
                    postTags = "</span></strong>",
                    fragmentSize = 500,
                    numberOfFragments = 3
            )
    )
    List<SearchHit<TbGoodsES>> findByGoodsName(String goodsName, Pageable p);

    @Highlight(
            fields = {
                    @HighlightField(name = "goodsName")
            },
            parameters = @HighlightParameters(
                    preTags = "<strong><span style='color:red'>",
                    postTags = "</span></strong>",
                    fragmentSize = 500,
                    numberOfFragments = 3
            )
    )
    List<SearchHit<TbGoodsES>> findByGoodsName(String goodsName);
}
